import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count:0,
    todos:[
      {
        id:'1',
        text:'伞兵一号',
        done: true
      },
      {
        id:'2',
        text:'伞兵二号',
        done: false
      },
      {
        id:'3',
        text:'伞兵三号',
        done: true
      }],
    userStatus: 3
  },
  getters:{
    userInfo(state){
      switch(state.userStatus){
        case 1:
          return '超级管理员';
          break;
        case 2:
          return '一般管理员';
          break;
        case 3:
          return '访客';
          break;
        default:
          break;
      }
    },
    doneTodos: state =>{
      return state.todos.filter(todos.todos.done);
    },
    doneTodosCount: (state,getters) =>{
      return getters.doneTodos.length;
    }
  },
  mutations: {
    add(state){
      state.count++
    },
    addN(state,step){
      state.count += step;
    }
  },
  actions: {
    addAsyc(context){
      setTimeout(()=>{context.commit('add')},3000);
    },
    addAsycN(context,step){
      setTimeout(()=>{
        context.commit('addN',step);
      },2000);
    },
  },
  modules: {
  }
})
